package com.example.alibabanacosdiscoveryclient01.config;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.context.annotation.Configuration;

/**
 * @author:guoq
 * @date:2024/7/10
 * @descripion:
 */
@Configuration
public class MyRequestOrigin implements RequestOriginParser {
    @Override
    public String parseOrigin(HttpServletRequest request) {
        String origin = request.getHeader("origin");
        if (StringUtils.isEmpty(origin)) {
           origin=request.getParameter("origin");
        }
        if(StringUtils.isEmpty(origin)){
            return "请求不合法";
        }

        return origin;
    }
}
